package com.qinglei.recoup.system.controller;

import com.qinglei.recoup.common.domain.CommonRes;
import com.qinglei.recoup.common.domain.Tree;
import com.qinglei.recoup.system.domain.Bed;
import com.qinglei.recoup.system.pojo.AddDeanBedParam;
import com.qinglei.recoup.system.service.DeanBedService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

@Api(tags = "[2.0新增]院长相关控制器-石 已完成")
@Slf4j
@Validated
@RestController
@RequestMapping("dean")
public class DeanController {

    @Autowired
    private DeanBedService deanBedService;

    /**
     * 给院长添加关联的床位
     *
     * @param param
     * @return
     */
    @ApiOperation(value = "给院长添加关联的床位")
    @PostMapping("/bed")
    public CommonRes<Object> addBed(@Valid @RequestBody AddDeanBedParam param) {
        deanBedService.addDeanBed(param);
        return CommonRes.ok();
    }

    /**
     * 删除院长关联的床位
     *
     * @param deanBedId
     * @return
     */
    @ApiOperation(value = "删除院长关联的床位")
    @DeleteMapping("/bed/{deanBedId}")
    public CommonRes<Object> delBed(@PathVariable @NotNull Integer deanBedId) {
        deanBedService.removeById(deanBedId);
        return CommonRes.ok();
    }

    @ApiOperation(value = "管理员端 院长关联床位 获取床位树形列表(床位是否可用)-已完成 id,title,type(类型 1-床位 2-房间 3-层 4-楼 5-全部床位)，value（床位数量）")
    @ApiImplicitParam(name = "userId", value = "院长ID", paramType = "query", dataType = "int", required = false)
    @GetMapping("/bedTree")
    public CommonRes<Tree<Bed>> getBedTree4Dean(Long userId) {
        Tree<Bed> bedTree4Dean = deanBedService.getBedTree4Dean(userId);
        return CommonRes.ok(bedTree4Dean);
    }
}
